<?php

//Tao Lop DOI_TUONG
class Truong {

    private $_TRUONG_ID;
    private $_BEP_ID;
    private $_TRUONG_TEN_TRUONG;
    private $_IS_ACTIVE;

    public function getTRUONG_ID() {
        return $this->_TRUONG_ID;
    }

    public function getBEP_ID() {
        return $this->_BEP_ID;
    }

    public function getTRUONG_TEN_TRUONG() {
        return $this->_TRUONG_TEN_TRUONG;
    }

    public function setTRUONG_ID($TRUONG_ID) {
        $this->_TRUONG_ID = $TRUONG_ID;
    }

    public function setBEP_ID($BEP_ID) {
        $this->_BEP_ID = $BEP_ID;
    }

    public function setTRUONG_TEN_TRUONG($TRUONG_TEN_TRUONG) {
        $this->_TRUONG_TEN_TRUONG = $TRUONG_TEN_TRUONG;
    }

        public function getIS_ACTIVE() {
        return $this->_IS_ACTIVE;
    }
    public function setIS_ACTIVE($IS_ACTIVE) {
        $this->_IS_ACTIVE = $IS_ACTIVE;
    }
       public function SetTruong($row) {
        $this->setTRUONG_ID($row->TRUONG_ID);
        $this->setBEP_ID($row->BEP_ID);
         $this->setTRUONG_TEN_TRUONG($row->TRUONG_TEN_TRUONG);
        $this->setIS_ACTIVE($row->IS_ACTIVE);
    }

 
    public function insert($db = null) {
        if ($db != null) {
            $sql = "INSERT INTO `truong`
                                (
                                 
                                 `BEP_ID`,
                                 `TRUONG_TEN_TRUONG`,
                                 `IS_ACTIVE`
)
                    VALUES (
                                 :BEP_ID,
                                 :TRUONG_TEN_TRUONG,
                                 :IS_ACTIVE);";
            $parameters = array(
                ":BEP_ID",
                ":TRUONG_TEN_TRUONG",
                ":IS_ACTIVE"
            );
            $values = array(
                
                $this->getBEP_ID(),
                $this->getTRUONG_TEN_TRUONG(),
                1);
            $types = array(
                PDO::PARAM_INT,
                PDO::PARAM_STR,
                PDO::PARAM_INT
            );
            $lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
            $this->setTRUONG_ID($lastInsertID);
        }
    }

    public function delete($db = null) {
        if ($db != null) {
            $sql = "delete
                    from `truong`
                    where `TRUONG_ID` = :TRUONG_ID;";
            $parameters = array(":TRUONG_ID");
            $values = array($this->getTRUONG_ID());
            $types = array(PDO::PARAM_INT);
            $result = $db->executeNonQuery($sql, $parameters, $values, $types);
            return $result;
        }
    }

    public function update($db = null) {
        if ($db != null) {
            $sql = "UPDATE `truong`
                    SET  `BEP_ID`=:BEP_ID,
                         `TRUONG_TEN_TRUONG`=:TRUONG_TEN_TRUONG
                    WHERE `TRUONG_ID` = :TRUONG_ID;";
            $parameters = array(
                ":TRUONG_ID", ":BEP_ID",
                ":TRUONG_TEN_TRUONG"
            );
            $values = array(
                $this->getTRUONG_ID(), $this->getBEP_ID(),
                $this->getTRUONG_TEN_TRUONG());
            $types = array(
                PDO::PARAM_INT,PDO::PARAM_INT,
                PDO::PARAM_STR
            );
            $result = $db->executeNonQuery($sql, $parameters, $values, $types);
            return $result;
        }
    }

    public function getByID($db = null) {
        if ($db != null) {
            $sql = "SELECT
                         `TRUONG_ID`,
                         `BEP_ID`,
                          `TRUONG_TEN_TRUONG`,
                            `IS_ACTIVE`
                      FROM `truong`
                      WHERE TRUONG_ID = :TRUONG_ID";
            $parameters = array(":TRUONG_ID");
            $values = array($this->getTRUONG_ID());
            $types = array(PDO::PARAM_INT);
            $rows = $db->executeQuery($sql, $parameters, $values, $types);
            if ($rows != null) {
                $row = $rows->fetch();
                    $this->setTRUONG_ID($row->TRUONG_ID);
                    $this->setBEP_ID($row->BEP_ID);
                    $this->setTRUONG_TEN_TRUONG($row->TRUONG_TEN_TRUONG);
                    $this->setIS_ACTIVE($row->IS_ACTIVE);
            }
            return $this;
        }
    }

    public function getList($db = null) {
        if ($db != null) {
            $sql = "SELECT
                         `TRUONG_ID`,
                         `BEP_ID`,
                          `TRUONG_TEN_TRUONG`,
                            `IS_ACTIVE`
                      FROM `truong`";
            $rows = $db->executeQuery($sql);
            $objects = array();
            if ($rows != null) {
                while ($row = $rows->fetch()) {
                    $truong = new Truong();
                    $truong->setTRUONG_ID($row->TRUONG_ID);
                    $truong->setBEP_ID($row->BEP_ID);
                    $truong->setTRUONG_TEN_TRUONG($row->TRUONG_TEN_TRUONG);
                    $truong->setIS_ACTIVE($row->IS_ACTIVE);

                    $objects[] = $truong;
                }
                return $objects;
            }
        }
    }

}
